########################################
# Who wants an independent court?
# Leiras, Giraudy, Tunon & Wagner.
# Replication file. Functions
########################################

# functions

province <- function(x){
  # uses: 
  # survival <- with(figs.data, Surv(total_tenure, outin2008 == 1))
  provinces.fit <- survfit(survival ~ figs.data$province==x)
  plot(provinces.fit, main=province.name[x], conf.int = FALSE,  mark.time=F,
       col=c("White", "Navy"), lwd=2)}


province.pol <- function(x){
  provinces.fit <- survfit(survival2 ~ pol.data$province==x)
  plot(provinces.fit, main=province.name[x], conf.int = FALSE,  mark.time=F,
       col=c("White", "Navy"), lwd=2)}



### function to get multinom model output for latex
summ.to.table <- function(x){
  temp <- summary(x)
  coef <- t(temp$coefficients)
  SE <- t(temp$standard.errors)
  vars <- rownames(temp$coefficients)
  table <- cbind (coef[,1], SE[,1], coef[,2], SE[,2], coef[,3], SE[,3] )
  colnames(table) <- c("Nat Exit Coef", "Nat Exit SEs", 'Pol Exit Coef', 
                       "Pol Exit SEs", "FI Coef", "FI SEs")
  print(table)
  xtable(table, digits=3)
}


# function to plot predicted effects
plot.pred <- function(x, title, xtitle){
  plot(c(0,1), x[,3],
       col="Navy Blue", ylim=c(0.1, 0.6), pch=15, cex=2, ylab="", xaxt="n",
       main=title, xlab=xtitle)
  axis(1, at=c(0,1), labels=c("0", "1"))
  lines(c(0,1), x[,3],
        col="Navy Blue", lwd=1, lty=4)
  points(c(0,1), x[,1],
         col="Gray 82", pch=15, cex=2)
  lines(c(0,1), x[,1],
        col="Gray 82", lwd=1, lty=4)  
}